home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / rint.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  887b  |  35 lines

  1. /*
  2.  * PDC I/O Library Copyright (C) 1987 by J.A. Lydiatt.
  3.  * Modifications for PDC release 3.3 Copyright (C) 1988 Lionel D. Hummel.
  4.  * PDC Software Distribution Copyright (C) 1988 Lionel Hummel and Paul Petersen.
  5.  *
  6.  * This code is freely redistributable upon the conditions that this notice
  7.  * remains intact and that modified versions of this file not be included
  8.  * as part of the PDC Software Distribution without the express consent of
  9.  * the copyright holders.
  10.  */
  11.  
  12. #include <math.h>
  13.  
  14. /*    round.c - performs rounding
  15.  */
  16.  
  17. /* Returns an integer rounded from a double.  In case of fraction exactly
  18.  * midway, round chooses nearest even value.
  19.  */
  20. double rint(num)
  21. double num;
  22. {
  23.     double ipart;
  24.     int    ival;
  25.     double frac;
  26.  
  27.     frac = modf(num, &ipart);
  28.  
  29.     ival = ipart;
  30.     if ( (frac > 0.5) || ((frac == 0.5) && (ival%2)) )
  31.         ival++;
  32.  
  33.     return((double) ival);
  34. }
  35.